import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

ColumnLayout{
    spacing:5
    anchors.fill: parent
    //心率图
    Rectangle{
        id:rrIntervalChart
        Layout.fillWidth:true
        Layout.preferredHeight: 160
        signal chartSelectedRangeChange(int start,int duration)
        RrIntervalChart{
            onSelectedRangeChange:function(start,duration) {
                rrIntervalChart.chartSelectedRangeChange(start,duration)
                rrScatter.resetCircleSelect()
            }
        }
    }
    //下半部分
    Rectangle{
        Layout.fillWidth:true
        Layout.fillHeight:true
        color:"transparent"
        // color: "red"
        RowLayout{
            spacing:5
            anchors.fill: parent
            //左侧散点图
            Rectangle{
                Layout.preferredWidth :parent.width > 1600? 550:450
                Layout.fillHeight:true
                Column{
                    anchors.fill: parent
                    spacing:5
                    //心搏数据显示区域
                    Rectangle{
                        width: parent.width
                        height: 46
                        Row{
                            anchors.centerIn: parent
                            height: parent.height-20
                            // y:10
                            spacing:10
                            // anchors.rightMargin: 5
                            Text {
                                color:"#666666"
                                font.pixelSize: 14
                                text: `共${gridViewBeatsList.beatsCount}个心搏`
                                verticalAlignment: Text.AlignVCenter  // 垂直居中
                                height:parent.height
                            }
                            CustomButton{
                                text:"全选"
                                width: 70
                                height:parent.height
                            }
                            Text {
                                color:"#666666"
                                font.pixelSize: 14
                                text: `已选中${beatsModel.selectedBeatsCount}个心搏`
                                verticalAlignment: Text.AlignVCenter  // 垂直居中
                                height:parent.height
                            }
                            CustomButton{
                                text:"叠加图"
                                plain:true
                                width: 70
                                height:parent.height
                            }
                        }
                    }

                    //散点图区域
                    Rectangle{
                        width: parent.width
                        height: parent.width
                        RrScatter{
                            id:rrScatter
                            onListDataChanged:function(){
                                //数据更新，修改列表高亮
                                myBeatsGrid.setCurrentIndex()
                            }
                        }
                    }
                    //类型切换区域
                    Rectangle{
                        width: parent.width
                        height: 20
                        Row{
                            spacing:5
                            anchors.fill: parent
                            id:switchLabels

                            signal currentLabelsChange(string label1,string label2)
                            property string currentLabels: "RR"
                            Text {
                                verticalAlignment: Text.AlignVCenter  // 垂直居中
                                height:parent.height
                                text:"类型:"
                                color:"#666"
                            }
                            Repeater{
                                model: [{name:"RR",label1:"",label2:""},
                                    {name:"NN",label1:"N",label2:"N"},
                                    {name:"RV",label1:"",label2:"V"},
                                    {name:"RS",label1:"",label2:"S"},
                                    {name:"AA",label1:"A",label2:"A"},
                                    {name:"RO",label1:"",label2:"O"},
                                    {name:"RX",label1:"",label2:"X"},
                                ]
                                CustomButton{
                                    text:modelData.name
                                    width: 50
                                    height:parent.height
                                    plain:switchLabels.currentLabels === modelData.name?false:true
                                    // 连接信号和槽
                                    onButtonClicked: {
                                        if(switchLabels.currentLabels !== modelData.name){
                                            switchLabels.currentLabels = modelData.name
                                            switchLabels.currentLabelsChange(modelData.label1,modelData.label2)
                                            rrScatter.resetCircleSelect()
                                        }
                                    }
                                }
                            }
                        }
                    }
                    Rectangle{
                        width: parent.width
                        height: 20
                        Row{
                            spacing:5
                            anchors.fill: parent
                            id:switchAxisMaxValue

                            signal axisMaxValueChange(int newValue)
                            property int axisMaxValue: 2000
                            Text {
                                verticalAlignment: Text.AlignVCenter  // 垂直居中
                                height:parent.height
                                text:"范围:"
                                color:"#666"
                            }
                            Repeater{
                                model: [2000,3000,4000,5000]
                                CustomButton{
                                    text:modelData.toString()
                                    plain:switchAxisMaxValue.axisMaxValue == modelData?false:true
                                    width: 50
                                    height:parent.height
                                    onButtonClicked: {
                                        if(switchAxisMaxValue.axisMaxValue != modelData){
                                            switchAxisMaxValue.axisMaxValue = modelData
                                            switchAxisMaxValue.axisMaxValueChange(modelData)
                                            rrScatter.resetCircleSelect()
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

            }
            //右侧心搏列表
            Rectangle{
                Layout.fillWidth:true
                Layout.fillHeight:true
                color:"transparent"
                // color:"red"
                ColumnLayout{
                    anchors.fill: parent
                    spacing:5
                    //心搏列表
                    Rectangle{
                        color: "#efefef"
                        Layout.fillWidth:true
                        Layout.fillHeight:true
                        Beats{
                            id: myBeatsGrid
                        }
                    }
                    //心电图预览
                    Rectangle{
                        color: "#ffffff"
                        Layout.fillWidth:true
                        Layout.preferredHeight: parent.height*0.4
                        EcgFragment{

                        }
                    }
                }
            }
        }
    }
}
